package com.sqx.modules.health.controller;/*
package com.sqx.modules.health.controller;

import com.sqx.modules.health.common.Constants;
import com.sqx.modules.health.common.Result;
import com.sqx.modules.health.dto.ServiceOrderDTO;
import com.sqx.modules.health.entity.NcgService;
import com.sqx.modules.health.service.INcgServiceService;
import com.sqx.modules.health.utils.HttpUtils;
import com.sqx.modules.health.utils.WxUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Map;
import java.util.Random;

@Slf4j
@Api(tags = "微信支付接口")
@RestController
@RequestMapping("/health/pay")
public class WeiXinPayController {

    @Autowired(required = false)
    private INcgServiceService service;

    @GetMapping("/WeiXinPay")
    public Result weiXinPay(HttpServletRequest request) throws Exception {
        // 获取用户的IP地址  下单必备参数
        String ipAddress = HttpUtils.getIpAddress(request);

        // 获取服务的id
        String serviceId = request.getParameter("serviceid");
        if (StringUtils.isEmpty(serviceId)) {
            return Result.error(Constants.CODE_500, "所选服务不存在");
        }

        // 根据服务的id 获取对应的服务项目
        NcgService ncgService = service.getById(serviceId);
        if (ncgService == null) {
            return Result.error(Constants.CODE_500, "所选服务不存在");
        }

        // 获取当前时间戳
        long millis = System.currentTimeMillis();
        Random random = new Random();
        // 生成订单号
        String orderNo = String.valueOf(millis + random.nextInt(100000));

        // 测试付一分钱
        BigDecimal amount = BigDecimal.valueOf(0.01);

        ServiceOrderDTO prepaidOrder = new ServiceOrderDTO();
        // 服务id
        prepaidOrder.setServiceId(Integer.valueOf(serviceId));
        // 用户的openid
        prepaidOrder.setOpenId(request.getParameter("openid"));
        prepaidOrder.setUserIp(ipAddress);  // 这个是微信需要的参数 userIp
        prepaidOrder.setAmount(ncgService.getCost()); // 这个是微信需要的参数 total_fee
        prepaidOrder.setOrderNumber(orderNo); // 这个是微信需要的参数   out_trade_no
        prepaidOrder.setBody(ncgService.getName());
        // 添加预付订单
        // 组装统一下单需要的数据map
        Map<String, String> stringStringMap = prepaidOrder.toWxPayParameters();
        // 调取统一支付
        Map<String, String> payParameters =  WxUtil.unifiedOrder(stringStringMap);
        return Result.success(payParameters);// 返回预付订单
    }


}
*/
